package com.atstudy.date;

import java.util.Calendar;
import java.util.Date;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/21 14:20
 * @copyright: 博为峰
 */
public class CalendarDemo {
    public static void main(String[] args) {
        //工厂方法
        Calendar instance = Calendar.getInstance();
//        System.out.println(instance);
        //Date -> Calendar
        instance.setTime(new Date());
//        m2(instance);
        m1(instance);
    }

    private static void m2(Calendar instance) {
        instance.set(2020, 11, 11);
        //加减
        instance.add(Calendar.YEAR, -5);
    }

    private static void m1(Calendar instance) {
        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH) + 1; //从0开始
        int day = instance.get(Calendar.DAY_OF_MONTH);
        int hour = instance.get(Calendar.HOUR_OF_DAY);//24小时制
        int minute = instance.get(Calendar.MINUTE);
        int second = instance.get(Calendar.SECOND);
        System.out.println(year + "年" + month + "月" + day + " " + hour + ":" + minute + ":" + second);
    }
}
